//
//  CarEditCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/8/6.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "CarEditCell.h"

@interface CarEditCell ()

@property (nonatomic, strong) UILabel *carNOLab;
@property (nonatomic, strong) UILabel *typeLab;
@property (nonatomic, strong) UILabel *vTitleLab;
@property (nonatomic, strong) UILabel *vLab;
@property (nonatomic, strong) UILabel *modelTitleLab;
@property (nonatomic, strong) UILabel *modelLab;
//@property (nonatomic, strong) UILabel *driverTitleLab;
//@property (nonatomic, strong) UILabel *driverLab;
@property (nonatomic, strong) UIButton *operationBtn;
@property (nonatomic, strong) UILabel *line;

@end

@implementation CarEditCell

+ (instancetype)CarEditCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"CarEditCell";
    CarEditCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[CarEditCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = HexColor(0xffffff);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.carNOLab = [UILabel new];
        self.carNOLab.textColor = HexColor(0x2B2C44);
        self.carNOLab.font = BoldFontOfSize(18);
        [self.contentView addSubview:self.carNOLab];
        
        self.typeLab = [UILabel new];
        self.typeLab.textColor = HexColor(0x3D68EB);
        self.typeLab.font = BoldFontOfSize(12);
        self.typeLab.backgroundColor = HexColorA(0x3D68EB, 0.1);
        self.typeLab.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.typeLab];
        
        self.vTitleLab = [UILabel new];
        self.vTitleLab.textColor = HexColor(0x9C9DB3);
        self.vTitleLab.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.vTitleLab];
        
        self.vLab = [UILabel new];
        self.vLab.textColor = HexColor(0x2B2C44);
        self.vLab.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.vLab];
        
        self.modelTitleLab = [UILabel new];
        self.modelTitleLab.textColor = HexColor(0x9C9DB3);
        self.modelTitleLab.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.modelTitleLab];
        
        self.modelLab = [UILabel new];
        self.modelLab.textColor = HexColor(0x2B2C44);
        self.modelLab.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.modelLab];
        
//        self.driverTitleLab = [UILabel new];
//        self.driverTitleLab.textColor = HexColor(0x9C9DB3);
//        self.driverTitleLab.font = [UIFont systemFontOfSize:14];
//        [self.contentView addSubview:self.driverTitleLab];
//
//        self.driverLab = [UILabel new];
//        self.driverLab.textColor = HexColor(0x2B2C44);
//        self.driverLab.font = [UIFont systemFontOfSize:14];
//        [self.contentView addSubview:self.driverLab];
        
        self.operationBtn = [UIButton new];
        [self.operationBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.operationBtn];
        
        self.line = [UILabel new];
        self.line.backgroundColor = Color_backgroundColor;
        [self.contentView addSubview:self.line];
    }
    return self;
}

- (void)btnClick {
    if (self.chooseBlock) {
        self.chooseBlock();
    }
}

-(void)setModel:(CarMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.carNOLab.text = self.model.num;
    [self.carNOLab sizeToFit];
    self.carNOLab.nim_left = 58;
    self.carNOLab.nim_top = 20;
    
    self.typeLab.text = self.model.car_type;
    [self.typeLab sizeToFit];
    self.typeLab.nim_left = self.carNOLab.nim_right + 10;
    self.typeLab.nim_width += 24;
    self.typeLab.nim_height += 6;
    self.typeLab.nim_centerY = self.carNOLab.nim_centerY;
    self.typeLab.layer.masksToBounds = YES;
    self.typeLab.layer.cornerRadius = self.typeLab.nim_height * 0.5;
    
    self.vTitleLab.text = @"最大装载量：";
    [self.vTitleLab sizeToFit];
    self.vTitleLab.nim_left = self.carNOLab.nim_left;
    self.vTitleLab.nim_top = self.carNOLab.nim_bottom + 8;
    
    self.vLab.text = [NSString stringWithFormat:@"%.2fkg / %.2fm³",self.model.max_weight,self.model.max_volume];
    [self.vLab sizeToFit];
    [self.vLab sizeToFit];
    self.vLab.nim_left = self.vTitleLab.nim_right;
    self.vLab.nim_centerY = self.vTitleLab.nim_centerY;
    
    self.modelTitleLab.text = @"车型：";
    [self.modelTitleLab sizeToFit];
    self.modelTitleLab.nim_left = self.carNOLab.nim_left;
    self.modelTitleLab.nim_top = self.vTitleLab.nim_bottom + 5;
    
    self.modelLab.text = self.model.car_info;
    [self.modelLab sizeToFit];
    self.modelLab.nim_left = self.modelTitleLab.nim_right;
    self.modelLab.nim_centerY = self.modelTitleLab.nim_centerY;
    
//    self.driverTitleLab.text = @"司机：";
//    [self.driverTitleLab sizeToFit];
//    self.driverTitleLab.nim_left = ScreenW * 0.7;
//    self.driverTitleLab.nim_centerY = self.modelTitleLab.nim_centerY;
//
//    self.driverLab.text = self.model.name;
//    [self.driverLab sizeToFit];
//    self.driverLab.nim_left = self.driverTitleLab.nim_right;
//    self.driverLab.nim_centerY = self.driverTitleLab.nim_centerY;
    
    self.line.frame = CGRectMake(0, self.modelTitleLab.nim_bottom + 16, ScreenW, 1);
    self.height = self.line.nim_bottom;
    
    self.operationBtn.nim_width = 23;
    self.operationBtn.nim_height = 23;
    self.operationBtn.nim_left = 15;
    self.operationBtn.nim_top = (self.height - self.operationBtn.nim_height) * 0.5;
    if (self.model.isSelected) {
        [self.operationBtn setImage:[UIImage imageNamed:@"icon_choice_sel"] forState:0];
    }else {
        [self.operationBtn setImage:[UIImage imageNamed:@"icon_backBox_choice"] forState:0];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
